{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "Ammsqa3"

// By ArtemQa146

const
    Process = 30@ //   
    gun_obj = 31@
    Background = 29@
    sniper = 27@
    Move_Weapon = 28@ //
    Move_Weapon_Step = 60
    Move_Weapon_Step_2 = 120
    angle_1 = 26@
end

0085: 4@ = $AMMU_SELECTED_WEAPON_MODEL // (int)
0085: Background = 0@ // (int)
0085: sniper = 1@ // (int)
model.Load(4@)
038B: load_requested_models
0400: store_coords_to 1@ 2@ 3@ from_object sniper with_offset 0.0 0.0 -0.45
0E01: create_object_no_save 4@ at 1@ 2@ 3@ offset 0 ground 0 to gun_obj
model.Destroy(4@)
0176: 1@ = object sniper Z_angle
0177: set_object gun_obj Z_angle_to 1@



Process = 0
Move_Weapon = 1

repeat
wait 0
0400: store_coords_to 1@ 2@ 3@ from_object Background with_offset 0.0 0.0 0.0
09E5: create_flash_light_at 1@ 2@ 3@ RGB_mask 255 255 255 radius 25.0 //  ,    

if
    Process == 0
then
    gosub @Camera_Position_Gun
    gosub @Camera_Move
    Process = 1
    0176: angle_1 = object sniper Z_angle
end

        if and
            $AMMU_STAGE == 7
            Process == 1
        then
            gosub @Camera_Position_Gun
            gosub @Weapon_rotate
            015F: set_camera_position 1@ 2@ 3@ rotation 0.0 0.0 0.0
            0160: set_camera_point_at 4@ 5@ 6@ switchstyle 1
            if or
                00E1:   player 0 pressed_key 15 // F/Enter
                $AMMU_SELLER_ANIMATION_TIME >= 0.1
            then
                0177: set_object gun_obj Z_angle_to angle_1
                Process = 2
            end
        end
        
        //      
        if
            Process == 2
        then
            gosub @Camera_Position
            gosub @Camera_Move
            Process = 3
            timera = 0
        end
        
        //   ,    ,           
        if and
            Process == 1
            Move_Weapon <= Move_Weapon_Step
            not Move_Weapon == 0
        then
            Move_Weapon += 1
            0400: store_coords_to 1@ 2@ 3@ from_object gun_obj with_offset 0.0 0.01 0.0
            01BC: put_object gun_obj at 1@ 2@ 3@
        end

        //       ,  
        if and
            Move_Weapon <= Move_Weapon_Step_2
            Move_Weapon >= Move_Weapon_Step
            Process == 3
        then
            Move_Weapon += 1
            0400: store_coords_to 1@ 2@ 3@ from_object gun_obj with_offset 0.0 -0.01 0.0
            01BC: put_object gun_obj at 1@ 2@ 3@
        end

        if and
            $AMMU_STAGE == 6
            Process == 3
        then
            Process = 4
        end

if or
    $AMMU_STAGE == 5
    Process == 4
then
    break
end

until $AMMU_STAGE == 2
0108: destroy_object gun_obj
0A93: terminate_this_custom_script

//   
:Weapon_rotate
0A4A: store_joystick_X_offset_to 1@ Y_offset_to 2@ // X -    - ,     Z
if
    1@ > 0.5
then
    0176: 2@ = object gun_obj Z_angle
    1@ /= 2.0
    005B: 2@ += 1@  // (float)
    0453: set_object gun_obj XY_rotation 0@ 0.0 angle 2@
else
    if
        1@ < -0.5
    then
        0176: 2@ = object gun_obj Z_angle
        1@ /= 2.0
        1@ *= -1.0
        0063: 2@ -= 1@  // (float)
        0453: set_object gun_obj XY_rotation 0@ 0.0 angle 2@
    end
end
0A4A: store_joystick_X_offset_to 2@ Y_offset_to 1@ // Y -   - ,     X
if
    1@ > 0.5
then
    0176: 3@ = object gun_obj Z_angle
    1@ /= 2.0
    005B: 0@ += 1@  // (float)
        if 0@ > 89.0
        then 0@ = 89.0 //    ,  
        end
    0453: set_object gun_obj XY_rotation 0@ 0.0 angle 3@
else
    if
        1@ < -0.5
    then
        0176: 3@ = object gun_obj Z_angle
        1@ /= 2.0
        1@ *= -1.0
        0063: 0@ -= 1@  // (float)
            if 0@ < -89.0
            then 0@ = -89.0 //    ,  
            end
        0453: set_object gun_obj XY_rotation 0@ 0.0 angle 3@
    end
end
return

:Camera_Move
015F: set_camera_position 1@ 2@ 3@ rotation 0.0 0.0 0.0
0160: set_camera_point_at 4@ 5@ 6@ switchstyle 1
return

//   .       . Weapon_show -   10@(Weapon_show,1i)
:Camera_Position_Gun
4@ = 0.4
5@ = 1.7
6@ = 0.1

0400: store_coords_to 1@ 2@ 3@ from_object gun_obj with_offset 4@ 5@ 0.1
0400: store_coords_to 4@ 5@ 6@ from_object gun_obj with_offset 6@ 0.0 0.0
return

:Camera_Position
0400: store_coords_to 1@ 2@ 3@ from_object Background with_offset 3.0 0.5 0.7
0400: store_coords_to 4@ 5@ 6@ from_object Background with_offset 7.1 3.2 -0.2
return